class Solution(object):
    def majorityElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 1:
            return nums[0]
        count = 1
        pre = nums[0]
        for i in range(1, len(nums)):
            if nums[i] == pre:
                count += 1
            else:
                if count == 0:
                    count = 1
                    pre = nums[i]
                else:
                    count -= 1
        return pre
